package com.mqb;

import java.time.LocalDateTime;

/**
 * 服务器主动向客户端推送的消息属于 NotifyMsg
 */
public class NotifyMsg extends BaseMsg{
    private final static String DEFAULT_SEND_ID  = "server";

    /**
     * 发送者id
     */
    private String sendId;

    /**
     * 消息内容
     */
    private String content;

    public NotifyMsg() {
    }

    public NotifyMsg(String id, String recId, LocalDateTime dateTime, String content) {
        super.id = id;
        super.msgType = MsgType.NOTIFY.getCode();
        super.recId = recId;
        this.sendId = DEFAULT_SEND_ID;
        super.dateTime = dateTime;
        this.content = content;
    }

    public NotifyMsg(String id, String recId, String sendId, LocalDateTime dateTime, String content) {
        super.id = id;
        super.msgType = MsgType.NOTIFY.getCode();
        super.recId = recId;
        this.sendId = sendId;
        super.dateTime = dateTime;
        this.content = content;
    }

    public static NotifyMsg transferToNotifyMsg(RequestMsg requestMsg){
        return new NotifyMsg(requestMsg.getId(),
                requestMsg.getRecId(),
                requestMsg.getSendId(),
                requestMsg.getDateTime(),
                requestMsg.getContent());
    }
}
